package com.ycsj.goldmedalnewconcept.adapter;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.view.inputmethod.InputMethodManager;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.BaseAdapter;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.PopupWindow;
import android.widget.TextView;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;

import com.flyco.dialog.listener.OnBtnLeftClickL;
import com.flyco.dialog.listener.OnBtnRightClickL;
import com.flyco.dialog.widget.NormalDialog;
import com.squareup.picasso.Picasso;
import com.ycsj.goldmedalnewconcept.bean.QuanziResponse;
import com.ycsj.goldmedalnewconcept.bean.QuanziResponse.CircleInfo;
import com.ycsj.goldmedalnewconcept.utils.ListViewUtil;
import com.ycsj.goldmedalnewconcept.utils.SPUtil;
import com.ycsj.goldmedalnewconcept.utils.TimeUtil;
import com.ycsj.goldmedalnewconcept.view.CommentsAdapter;
import com.ycsj.goldmedalnewconcept.view.ImageInfo;
import com.ycsj.goldmedalnewconcept.view.NineGridView;
import com.ycsj.goldmedalnewconcept.view.NineGridViewClickAdapter;
import com.ycsj.goldmedalnewconcept.R;

public class EvaluationAdapter extends BaseAdapter {

	private Context context;
	private List<CircleInfo> data = new ArrayList<QuanziResponse.CircleInfo>();
	private LayoutInflater mInflater;
	private Handler mHandler = new Handler();
	private int p;
	private String like = "";
	private String content;
	private Map<Integer,Integer> dianzanMap = new HashMap<Integer,Integer>();

	public void setData(List<CircleInfo> data) {
		this.data = data;
		notifyDataSetChanged();
	}

	public EvaluationAdapter(Context context, List<CircleInfo> data,
			Handler mHandler) {
		this.context = context;
		this.data = data;
		this.mHandler = mHandler;
		mInflater = LayoutInflater.from(context);
	}

	@Override
	public int getCount() {
		return data.size();
	}

	@Override
	public CircleInfo getItem(int position) {
		return (CircleInfo) data.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(final int position, View convertView, ViewGroup parent) {

		if (convertView == null) {
			convertView = mInflater.inflate(R.layout.item_evaluate, parent,
					false);
			convertView.setTag(new ViewHolder(convertView));
		}
		final ViewHolder holder = (ViewHolder) convertView.getTag();
		CircleInfo item = getItem(position);
		
		
		holder.content = (TextView) convertView.findViewById(R.id.tv_content);
		holder.nineGrid = (NineGridView) convertView.findViewById(R.id.nineGrid);
		holder.username = (TextView) convertView.findViewById(R.id.tv_username);
		holder.createTime = (TextView) convertView.findViewById(R.id.tv_createTime);
		holder.comments = (ListView) convertView.findViewById(R.id.lv_comments);
		holder.userpic = (ImageView) convertView.findViewById(R.id.userpic);
		holder.delete = (TextView) convertView.findViewById(R.id.delete);
		holder.tv_likelist = (TextView) convertView.findViewById(R.id.tv_likelist);
		
		// 点击昵称
		holder.username.setOnClickListener(new OnClickListener() {
			
			public void onClick(View v) {
				
				List<String> list3 = new ArrayList<String>();
				list3.add(data.get(position).user_id);
				list3.add(data.get(position).role);
				Message message = mHandler.obtainMessage();
				message.what = 4;
				message.obj = list3;
				mHandler.sendMessage(message); 
				
			}
		});
		// 点击头像
		holder.userpic.setOnClickListener(new OnClickListener() {
			
			public void onClick(View v) {
				List<String> list3 = new ArrayList<String>();
				list3.add(data.get(position).user_id);
				list3.add(data.get(position).role);
				Message message = mHandler.obtainMessage();
				message.what = 4;
				message.obj = list3;
				mHandler.sendMessage(message); 
			}
		});
		
		
		
		
		if (data.get(position).commentlist.size() == 0) {
			holder.comments.setVisibility(View.GONE);
		} else {	
			holder.comments.setVisibility(View.VISIBLE);
			holder.comments.setAdapter(new CommentsAdapter(context,
					data.get(position).commentlist));
			
			
			
			holder.comments.setOnItemClickListener(new OnItemClickListener() {

				@Override
				public void onItemClick(AdapterView<?> parent, View view,
						final int p, long id) {
					
					if(data.get(position).commentlist.get(p).user_id.equals(SPUtil.getString(context, "account", ""))){
						//删除评论
						final NormalDialog dialog = new NormalDialog(context);
						dialog.content("确定删除此条评论？").btnText("取消", "确认")
								.style(NormalDialog.STYLE_TWO).titleTextSize(23).show();
						dialog.setCanceledOnTouchOutside(false);
						dialog.setOnBtnLeftClickL(new OnBtnLeftClickL() {

							@Override
							public void onBtnLeftClick() {
								dialog.dismiss();
							}
						});

						dialog.setOnBtnRightClickL(new OnBtnRightClickL() {

							@Override
							public void onBtnRightClick() {
								
								List<String> list2 = new ArrayList<String>();
								list2.add(data.get(position).row_id + "");
								list2.add(data.get(position).commentlist.get(p).comment_id);
								
								Message message = mHandler.obtainMessage();
								message.what = 5;
								message.obj = list2;
								mHandler.sendMessage(message); // 发送消息
								dialog.dismiss();
							}
						});
					}else{
						//回复评论
						content = "";
						
						View editView = mInflater.inflate(
								R.layout.replay_input, null);
						
						
						holder.editWindow = new PopupWindow(editView,
								ViewGroup.LayoutParams.MATCH_PARENT,
								ViewGroup.LayoutParams.WRAP_CONTENT);
						holder.editWindow.setOutsideTouchable(true);
						holder.editWindow.setFocusable(true);
						holder.editWindow
								.setBackgroundDrawable(new ColorDrawable(
										Color.WHITE));
						final EditText replyEdit = (EditText) editView
								.findViewById(R.id.reply);
						
						replyEdit.setHint("回复"+data.get(position).commentlist.get(p).user_name+":");
						TextView send = (TextView) editView
								.findViewById(R.id.send_msg);
						
						replyEdit.setFocusable(true);
						replyEdit.requestFocus();
						// 以下两句不能颠倒
						holder.editWindow
								.setInputMethodMode(PopupWindow.INPUT_METHOD_NEEDED);
						holder.editWindow
								.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
						holder.editWindow.showAtLocation(
								holder.rootView, Gravity.BOTTOM, 0, 0);
						// 显示键盘
						final InputMethodManager imm = (InputMethodManager) context
								.getSystemService(Context.INPUT_METHOD_SERVICE);
						imm.toggleSoftInput(0,
								InputMethodManager.HIDE_NOT_ALWAYS);
						
						holder.editWindow
								.setOnDismissListener(new PopupWindow.OnDismissListener() {
									@Override
									public void onDismiss() {
										if (imm.isActive())
											imm.toggleSoftInput(
													0,
													InputMethodManager.RESULT_SHOWN);
									}
								});
						// 回复评论
						send.setOnClickListener(new OnClickListener() {

							@Override
							public void onClick(View v) {
								content = replyEdit.getText()
										.toString();
								Log.e("test", content);
								if (content == null
										|| "".equals(content)) {
									return;
								}
								
								List<String> list = new ArrayList<String>();
								list.add(data.get(position).row_id + "");
								list.add(data.get(position).commentlist.get(p).user_id);
								list.add(data.get(position).commentlist.get(p).role);
								list.add(content);
								
								
								Message message = mHandler
										.obtainMessage();
								message.what = 6;
								message.obj = list;
								mHandler.sendMessage(message); // 发送消息
								
								 
								 if (holder.editWindow != null){
									 holder.editWindow.dismiss();
								 }
							}
						});
					}
				}
			});
			ListViewUtil.setListViewHeightBasedOnChildren(holder.comments);
		}
		
		
		holder.tv_likelist.setText("");
		holder.tv_likelist.setVisibility(holder.tv_likelist.GONE);
		
		if(data.get(position).likelist!=null&&data.get(position).likelist.size()!=0){
			
			holder.tv_likelist.setVisibility(holder.tv_likelist.VISIBLE);
			
			like = "";
			for (int i = 0; i < data.get(position).likelist.size(); i++) {
				if("".equals(data.get(position).likelist.get(i).user_name)){
					like = like + SPUtil.getString(context, "name", "");
				}else{
					like = like + data.get(position).likelist.get(i).user_name;
				}
				
				
				if(i!=data.get(position).likelist.size()-1){
					like = like + " ";
				}
			}
			holder.tv_likelist.setText(like);
			
		}
		Iterator iter = dianzanMap.entrySet().iterator();
		while (iter.hasNext()) {
			Entry entry =  (Entry) iter.next();
		int key = (Integer) entry.getKey();
		int val = (Integer) entry.getValue();
		if(key==position){
			if(val==0){
				
				holder.tv_likelist.setText(holder.tv_likelist.getText().toString().replaceAll(SPUtil.getString(context, "name", ""), ""));
				like.replaceAll(SPUtil.getString(context, "name", ""), "");
				if("".equals(holder.tv_likelist.getText().toString().trim())){
					holder.tv_likelist.setVisibility(holder.tv_likelist.GONE);
				}
				
			}else if(val==1){
				holder.tv_likelist.setVisibility(holder.tv_likelist.VISIBLE);
				String s = holder.tv_likelist.getText().toString();
				if(!s.contains(SPUtil.getString(context, "name", ""))){
					holder.tv_likelist.setText(SPUtil.getString(context, "name", ""));
				}
				
			}
		}
		}
		
		
		
		holder.content.setText(data.get(position).content); 		// 消息内容
		if("".equals(data.get(position).user_name)){
			holder.username.setText(SPUtil.getString(context, "name", ""));
		}else{
			holder.username.setText(data.get(position).user_name);  // 昵称
		}
		
		
		if("".equals(data.get(position).user_pic)){
			
			Picasso.with(context).load(SPUtil.getString(context, "icon", ""))
			.into(holder.userpic); // 自己头像
		}else{
			Picasso.with(context).load(data.get(position).user_pic)
			.into(holder.userpic); // 头像 

		}
		
		
		String time = TimeUtil
				.getTimeFormatText(data.get(position).update_date);

		holder.createTime.setText(time); // 发布时间

//		"".equals(data.get(position).user_name)
		if(SPUtil.getString(context, "account", "").equals(data.get(position).user_id)
				&&SPUtil.getString(context, "role", "").equals(data.get(position).role)
				){
			holder.delete.setVisibility(holder.delete.VISIBLE);
		}else{
			holder.delete.setVisibility(holder.delete.GONE);
		}
		// 删除圈子消息
		holder.delete.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {

				final NormalDialog dialog = new NormalDialog(context);
				dialog.content("确定删除此条消息？").btnText("取消", "确认")
						.style(NormalDialog.STYLE_TWO).titleTextSize(23).show();
				dialog.setCanceledOnTouchOutside(false);
				dialog.setOnBtnLeftClickL(new OnBtnLeftClickL() {

					@Override
					public void onBtnLeftClick() {
						dialog.dismiss();
					}
				});

				dialog.setOnBtnRightClickL(new OnBtnRightClickL() {

					@Override
					public void onBtnRightClick() {
						// 删除条目
						dialog.dismiss();
						Message message = mHandler.obtainMessage();
						message.what = 2;
						message.obj = data.get(position).row_id;
						mHandler.sendMessage(message); // 发送消息
						
					}
				});
			}
		});

		holder.more = (ImageView) convertView.findViewById(R.id.more);

		holder.more.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				p = position;
				more(v); // 更多
			}

			public void more(View view) {
				View popupView = mInflater.inflate(R.layout.popup_reply, null);
				// 点赞
				
				
				TextView tv_favour = (TextView) popupView.findViewById(R.id.favour);
				
				if(!"".equals(holder.tv_likelist.getText().toString())&&
						holder.tv_likelist.getText().toString().contains(SPUtil.getString(context, "name", ""))){
					tv_favour.setText("取消");
				}else{
					tv_favour.setText(" 赞");
				}
				popupView.findViewById(R.id.favour).setOnClickListener(
						new OnClickListener() {

							@Override
							public void onClick(View v) {
								
								if(!"".equals(holder.tv_likelist.getText().toString())&&holder.tv_likelist.getText().toString().contains(SPUtil.getString(context, "name", ""))){
//									Log.e("testtt", holder.tv_likelist.getText().toString());
									dianzanMap.put(position, 0);
									
//									Toast.makeText(context, "取消赞",
//											Toast.LENGTH_SHORT).show();
									
									
									holder.tv_likelist.setText(holder.tv_likelist.getText().toString().replaceAll(SPUtil.getString(context, "name", ""), ""));
									like.replaceAll(SPUtil.getString(context, "name", ""), "");
									Message message = mHandler.obtainMessage();
									message.what = 3;
									message.obj = data.get(position).row_id;
									mHandler.sendMessage(message); // 发送消息
									if("".equals(holder.tv_likelist.getText().toString().trim())){
										holder.tv_likelist.setVisibility(holder.tv_likelist.GONE);
									}
									
								}else{
								holder.tv_likelist.setVisibility(holder.tv_likelist.VISIBLE);
								dianzanMap.put(position, 1);
								String s = holder.tv_likelist.getText().toString().trim();
								holder.tv_likelist.setText(SPUtil.getString(context, "name", "")+" "+s);
								
								
								Message message = mHandler.obtainMessage();
								message.what = 0;
								message.obj = data.get(position).row_id;
								mHandler.sendMessage(message); // 发送消息
								
//								Toast.makeText(context, "赞+1",
//										Toast.LENGTH_SHORT).show();
								}
								
								if (holder.window != null)
									holder.window.dismiss();
							}
						});
				
				// 评论
				popupView.findViewById(R.id.comment).setOnClickListener(
						new OnClickListener() {

							private String content = "";
							
							@Override
							public void onClick(View v) {
								// TODO Auto-generated method stub
								View editView = mInflater.inflate(
										R.layout.replay_input, null);
								holder.editWindow = new PopupWindow(editView,
										ViewGroup.LayoutParams.MATCH_PARENT,
										ViewGroup.LayoutParams.WRAP_CONTENT);
								holder.editWindow.setOutsideTouchable(true);
								holder.editWindow.setFocusable(true);
								holder.editWindow
										.setBackgroundDrawable(new ColorDrawable(
												Color.WHITE));
								final EditText replyEdit = (EditText) editView
										.findViewById(R.id.reply);
								TextView send = (TextView) editView
										.findViewById(R.id.send_msg);
								
								replyEdit.setFocusable(true);
								replyEdit.requestFocus();
								// 以下两句不能颠倒
								holder.editWindow
										.setInputMethodMode(PopupWindow.INPUT_METHOD_NEEDED);
								holder.editWindow
										.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
								holder.editWindow.showAtLocation(
										holder.rootView, Gravity.BOTTOM, 0, 0);
								// 显示键盘
								final InputMethodManager imm = (InputMethodManager) context
										.getSystemService(Context.INPUT_METHOD_SERVICE);
								imm.toggleSoftInput(0,
										InputMethodManager.HIDE_NOT_ALWAYS);
								
								holder.editWindow
										.setOnDismissListener(new PopupWindow.OnDismissListener() {
											@Override
											public void onDismiss() {
												if (imm.isActive())
													imm.toggleSoftInput(
															0,
															InputMethodManager.RESULT_SHOWN);
											}
										});
								// 发送评论
								send.setOnClickListener(new OnClickListener() {

									@Override
									public void onClick(View v) {
										content = replyEdit.getText()
												.toString();
										Log.e("test", content);
										if (content == null
												|| "".equals(content)) {
											return;
										}
										
										List<String> list = new ArrayList<String>();
										list.add(data.get(position).row_id + "");
										list.add(data.get(position).user_id);
										list.add(data.get(position).role);
										list.add(content);
										
										Message message = mHandler
												.obtainMessage();
										message.what = 1;
										message.obj = list;
										mHandler.sendMessage(message); // 发送消息
										
//										 Toast.makeText(context, "评论成功",
//										 Toast.LENGTH_SHORT).show();
										 
										 if (holder.editWindow != null){
											 holder.editWindow.dismiss();
										 }
									}
								});

								if (holder.window != null)
									holder.window.dismiss();
							}
						});
				
				// popupView.findViewById(R.id.delete)

				holder.window = new PopupWindow(popupView,
						ViewGroup.LayoutParams.WRAP_CONTENT,
						ViewGroup.LayoutParams.WRAP_CONTENT);
				holder.window.setOutsideTouchable(true);
				holder.window.setFocusable(true);
				// window.setAnimationStyle(R.style.popup_more_anim);
				holder.window.setBackgroundDrawable(new ColorDrawable(
						Color.BLACK));
				popupView.measure(0, 0);
				int xoff = -popupView.getMeasuredWidth();
				int yoff = -(popupView.getMeasuredHeight() + view.getHeight()) / 2;
				holder.window.showAsDropDown(view, xoff, yoff);
				
				//转发
				popupView.findViewById(R.id.zhuanfa).setOnClickListener(
						new OnClickListener() {

							@Override
							public void onClick(View v) {
								
								final NormalDialog dialog = new NormalDialog(context);
								dialog.content("确定转发此条消息？").btnText("取消", "确认")
										.style(NormalDialog.STYLE_TWO).titleTextSize(23).show();
								dialog.setCanceledOnTouchOutside(false);
								dialog.setOnBtnLeftClickL(new OnBtnLeftClickL() {

									@Override
									public void onBtnLeftClick() {
										dialog.dismiss();
									}
								});

								dialog.setOnBtnRightClickL(new OnBtnRightClickL() {

									@Override
									public void onBtnRightClick() {
										List<String> list = new ArrayList<String>();
										list.add(data.get(position).row_id + "");
										list.add(data.get(position).user_id);
										list.add(data.get(position).role);
										list.add(data.get(position).user_name);
										//转发
										dialog.dismiss();
										Message message = mHandler.obtainMessage();
										message.what = 7;
										message.obj = list;
										mHandler.sendMessage(message); 
										
									}
								});
								
								
								if (holder.window != null)
									holder.window.dismiss();
							}
						});
				
				
			}
		});
		
		ArrayList<ImageInfo> imageInfo = new ArrayList<ImageInfo>();
		
		if (data.get(position).s_user_picture1 != null
				&& !"".equals(data.get(position).s_user_picture1)) {
			ImageInfo info = new ImageInfo();
			info.setThumbnailUrl(data.get(position).s_user_picture1);
			info.setBigImageUrl(data.get(position).user_picture1);
			if (!"".equals(data.get(position).picture1_width)
					&& !"".equals(data.get(position).picture1_length)) {
				if (data.get(position).picture1_width != null
						&& data.get(position).picture1_length != null) {
					info.setImageViewWidth(Integer.parseInt(data.get(position).picture1_width));
					info.setImageViewHeight(Integer.parseInt(data.get(position).picture1_length));
				}
			}
			imageInfo.add(info);
		}
		
		if (data.get(position).s_user_picture2 != null
				&& !"".equals(data.get(position).s_user_picture2)) {
			ImageInfo info = new ImageInfo();
			info.setThumbnailUrl(data.get(position).s_user_picture2);
			info.setBigImageUrl(data.get(position).user_picture2);
			imageInfo.add(info);
		}
		
		if (data.get(position).s_user_picture3 != null
				&& !"".equals(data.get(position).s_user_picture3)) {
			ImageInfo info = new ImageInfo();
			info.setThumbnailUrl(data.get(position).s_user_picture3);
			info.setBigImageUrl(data.get(position).user_picture3);
			imageInfo.add(info);
		}
		if (data.get(position).s_user_picture4 != null
				&& !"".equals(data.get(position).s_user_picture4)) {
			ImageInfo info = new ImageInfo();
			info.setThumbnailUrl(data.get(position).s_user_picture4);
			info.setBigImageUrl(data.get(position).user_picture4);
			imageInfo.add(info);
		}
		if (data.get(position).s_user_picture5 != null
				&& !"".equals(data.get(position).s_user_picture5)) {
			ImageInfo info = new ImageInfo();
			info.setThumbnailUrl(data.get(position).s_user_picture5);
			info.setBigImageUrl(data.get(position).user_picture5);
			imageInfo.add(info);
		}
		if (data.get(position).s_user_picture6 != null
				&& !"".equals(data.get(position).s_user_picture6)) {
			ImageInfo info = new ImageInfo();
			info.setThumbnailUrl(data.get(position).s_user_picture6);
			info.setBigImageUrl(data.get(position).user_picture6);
			imageInfo.add(info);
		}
		if (data.get(position).s_user_picture7 != null
				&& !"".equals(data.get(position).s_user_picture7)) {
			ImageInfo info = new ImageInfo();
			info.setThumbnailUrl(data.get(position).s_user_picture7);
			info.setBigImageUrl(data.get(position).user_picture7);
			imageInfo.add(info);
		}
		if (data.get(position).s_user_picture8 != null
				&& !"".equals(data.get(position).s_user_picture8)) {
			ImageInfo info = new ImageInfo();
			info.setThumbnailUrl(data.get(position).s_user_picture8);
			info.setBigImageUrl(data.get(position).user_picture8);
			imageInfo.add(info);
		}
		if (data.get(position).s_user_picture9 != null
				&& !"".equals(data.get(position).s_user_picture9)) {
			ImageInfo info = new ImageInfo();
			info.setThumbnailUrl(data.get(position).s_user_picture9);
			info.setBigImageUrl(data.get(position).user_picture9);
			imageInfo.add(info);
		}

		holder.nineGrid.setAdapter(new NineGridViewClickAdapter(context,
				imageInfo));

		
		return convertView;
	}

	class ViewHolder {
		private TextView content;
		private NineGridView nineGrid;
		private TextView username;
		private TextView delete;
		private ImageView userpic;
		private TextView tv_likelist;
		
		private TextView createTime;
		private ListView comments;
		private PopupWindow window;
		private PopupWindow editWindow;
		private View rootView;
		private ImageView more;

		public ViewHolder(View convertView) {
			rootView = convertView;
//			content = (TextView) rootView.findViewById(R.id.tv_content);
//			nineGrid = (NineGridView) rootView.findViewById(R.id.nineGrid);
//			username = (TextView) rootView.findViewById(R.id.tv_username);
//			createTime = (TextView) rootView.findViewById(R.id.tv_createTime);
//			comments = (ListView) rootView.findViewById(R.id.lv_comments);
//			userpic = (ImageView) rootView.findViewById(R.id.userpic);
//			delete = (TextView) rootView.findViewById(R.id.delete);
//			tv_likelist = (TextView) rootView.findViewById(R.id.tv_likelist);
			NineGridView.setImageLoader(new PicassoImageLoader());
		} 

		/** Picasso 加载 */
		private class PicassoImageLoader implements NineGridView.ImageLoader {

			@Override
			public void onDisplayImage(Context context, ImageView imageView,
					String url) {
				Picasso.with(context).load(url)//
						.placeholder(R.drawable.temp)//
						.error(R.drawable.temp)// 
						.into(imageView);
			}

			@Override
			public Bitmap getCacheImage(String url) {
				
				return null;
			}
		}

		// public void more(View view) {
		// View popupView = mInflater.inflate(R.layout.popup_reply, null);
		// popupView.findViewById(R.id.favour).setOnClickListener(this);
		// popupView.findViewById(R.id.comment).setOnClickListener(this);
		// window = new PopupWindow(popupView,
		// ViewGroup.LayoutParams.WRAP_CONTENT,
		// ViewGroup.LayoutParams.WRAP_CONTENT);
		// window.setOutsideTouchable(true);
		// window.setFocusable(true);
		// // window.setAnimationStyle(R.style.popup_more_anim);
		// window.setBackgroundDrawable(new ColorDrawable(Color.BLACK));
		// popupView.measure(0, 0);
		// int xoff = -popupView.getMeasuredWidth();
		// int yoff = -(popupView.getMeasuredHeight() + view.getHeight()) / 2;
		// window.showAsDropDown(view, xoff, yoff);
		// }

		// public void delete(View view) {
		// final GlobalDialog delDialog = new GlobalDialog(context);
		// delDialog.setCanceledOnTouchOutside(true);
		// delDialog.getTitle().setText("提示");
		// delDialog.getContent().setText("确定删除吗?");
		// delDialog.setLeftBtnText("取消");
		// delDialog.setRightBtnText("确定");
		// delDialog.setLeftOnclick(new View.OnClickListener() {
		// @Override
		// public void onClick(View v) {
		// Toast.makeText(context, "取消", Toast.LENGTH_SHORT).show();
		// delDialog.dismiss();
		// }
		// });
		// delDialog.setRightOnclick(new View.OnClickListener() {
		// @Override
		// public void onClick(View v) {
		// Toast.makeText(context, "确定", Toast.LENGTH_SHORT).show();
		// delDialog.dismiss();
		// }
		// });
		// delDialog.show();
		// }

		// @Override
		// public void onClick(View v) {
		// switch (v.getId()) {
		// case R.id.favour:
		//
		// // dianzan();
		// Log.e("test","位置："+p);
		// Toast.makeText(context, "赞+1", Toast.LENGTH_SHORT).show();
		// if (window != null)
		// window.dismiss();
		// break;
		//
		// case R.id.comment:
		// View editView = mInflater.inflate(R.layout.replay_input, null);
		// editWindow = new PopupWindow(editView,
		// ViewGroup.LayoutParams.MATCH_PARENT,
		// ViewGroup.LayoutParams.WRAP_CONTENT);
		// editWindow.setOutsideTouchable(true);
		// editWindow.setFocusable(true);
		// editWindow
		// .setBackgroundDrawable(new ColorDrawable(Color.WHITE));
		//
		// EditText replyEdit = (EditText) editView
		// .findViewById(R.id.reply);
		// replyEdit.setFocusable(true);
		// replyEdit.requestFocus();
		// // 以下两句不能颠倒
		// editWindow.setInputMethodMode(PopupWindow.INPUT_METHOD_NEEDED);
		// editWindow
		// .setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
		// editWindow.showAtLocation(rootView, Gravity.BOTTOM, 0, 0);
		// // 显示键盘
		// final InputMethodManager imm = (InputMethodManager) context
		// .getSystemService(Context.INPUT_METHOD_SERVICE);
		// imm.toggleSoftInput(0, InputMethodManager.HIDE_NOT_ALWAYS);
		//
		// editWindow
		// .setOnDismissListener(new PopupWindow.OnDismissListener() {
		// @Override
		// public void onDismiss() {
		// if (imm.isActive())
		// imm.toggleSoftInput(0,
		// InputMethodManager.RESULT_SHOWN);
		// }
		// });
		// if (window != null)
		// window.dismiss();
		// break;
		//
		// case R.id.zhuanfa:
		// Toast.makeText(context, "转发", Toast.LENGTH_SHORT).show();
		// if (window != null)
		// window.dismiss();
		// break;
		//
		// case R.id.jubao:
		// Toast.makeText(context, "举报", Toast.LENGTH_SHORT).show();
		// if (window != null)
		// window.dismiss();
		// break;
		// }
		// }

	}
}
